package com.test27_二叉树;

import com.test27_二叉树.vo.Book;
import org.junit.Test;

import java.util.Arrays;

/**
 * 二叉树的遍历模式：
 * 前序遍历（根-左-右）
 * 中序遍历（左-根-右）
 * 后序遍历（左-右-根）
 */
public class YootkDemo_01 {

    @Test
    public void test1() {
        IBinaryTree<Integer> binaryTree = new BinaryTreeImpl<>();
        binaryTree.add(6);
        binaryTree.add(9);
        binaryTree.add(3);
        binaryTree.add(2);
        binaryTree.add(8);
        System.out.println("【元素个数】" + binaryTree.size());
        System.out.print("【二叉树数据】");
        for (Object obj : binaryTree.toArray()) {
            System.out.print(obj + "、");
        }
    }

    @Test
    public void test2() {
        IBinaryTree<Integer> binaryTree = new BinaryTreeImpl<>();
        binaryTree.add(6);
        binaryTree.add(9);
        binaryTree.add(3);
        binaryTree.add(2);
        binaryTree.add(8);
        System.out.println("【元素存在判断】" + binaryTree.contains(9));
        System.out.println("【元素存在判断】" + binaryTree.contains(10));
    }

    @Test
    public void test3() {
        IBinaryTree<Book> binaryTree = new BinaryTreeImpl<>();
        binaryTree.add(new Book("Java从入门到项目实战", "李兴华", 99.8));
        binaryTree.add(new Book("Python从入门到项目实战", "李兴华", 97.8));
        binaryTree.add(new Book("Go从入门到项目实战", "李兴华", 99.9));
        System.out.println("【元素存在判断】" + binaryTree.contains(new Book("Java从入门到项目实战", "李兴华", 99.8)));
        System.out.println("【元素存在判断】" + binaryTree.contains(new Book("JavaWEB从入门到项目实战", "李兴华", 89.9)));
        System.out.println("获取全部数据");
        Arrays.stream(binaryTree.toArray()).forEach(System.out::println);
    }

    @Test
    public void test4() {
        IBinaryTree<Integer> binaryTree = new BinaryTreeImpl<>();
        int[] numbers = {80, 50, 90, 30, 55, 60, 10, 85, 95};
        for (int num : numbers) {
            binaryTree.add(num);
        }
        System.out.println("【获取全部数据】" + Arrays.toString(binaryTree.toArray()));
        binaryTree.remove(50);
        binaryTree.remove(10);
        // binaryTree.remove(80);
        binaryTree.remove(90);
        System.out.println("【获取全部数据】" + Arrays.toString(binaryTree.toArray()));
    }
}
